package com.example.library_room.dao

import androidx.room.*
import com.example.library_room.db.UserDB
import io.reactivex.Single

@Dao
interface UserDao {
    //onConflict = OnConflictStrategy.REPLACE的意思是如果主键重复，用新的数据替换老数据
    //插入聊天记录的请求时间记录信息
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUser(user: UserDB): Single<Long>

    //批量插入数据
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun batchInsertUser(vararg users: UserDB): Single<List<Long>>

    //更新聊天记录
    @Update
    fun updateUser(user: UserDB): Single<Int>

    //根据消息主键获取消息信息
    @Query("SELECT * FROM user_db WHERE user_id = :id LIMIT 1")
    fun getUserById(id: Long): Single<UserDB>

    @Delete
    fun deleteUser(user: UserDB): Single<Int>
}